package com.bite.forum.dao;

import com.bite.forum.model.Article;
import com.bite.forum.model.Collect;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CollectMapper {

    @Insert("INSERT INTO t_collect (articleId, userId, createTime, updateTime, status) VALUES (#{articleId}, #{userId}, #{createTime}, #{updateTime}, #{status})")
    void insert(Collect collect);

    @Update("update t_collect set status = #{status}, updateTime = #{updateTime} where articleId = #{articleId} and userId = #{userId}")
    void update(Collect collect);

    @Select("SELECT * FROM t_collect WHERE articleId = #{articleId} AND userId = #{userId} LIMIT 1")
    Collect findByArticleIdAndUserId(@Param("articleId") Long articleId, @Param("userId") Long userId);

    @Select("SELECT a.id, a.title, a.createTime FROM t_collect c JOIN t_article a on c.articleId = a.id WHERE c.userId = #{userid} and c.status = 1")
    List<Article> selectListByUserId(Long userid);
}